using Assets.Scripts.GDK;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class BallMove : gdk_base_UI
	{
		private float timer;

		public BallState state;

		public Sprite[] ballSp;

		private Image ballImg;

		private void OnCollisionEnter2D(Collision2D collision)
		{
		}

		private void OnCollisonStay2D(Collision2D collision)
		{
			if (!collision.gameObject.CompareTag("Enemy"))
			{
				return;
			}
			timer += Time.deltaTime;
			if (timer > 1f)
			{
				switch (Random.Range(0, 4))
				{
					case 0:
						GetComponent<Rigidbody2D>().AddForce(base.transform.up * 0.01f);
						break;
					case 1:
						GetComponent<Rigidbody2D>().AddForce(-base.transform.up * 0.01f);
						break;
					case 2:
						GetComponent<Rigidbody2D>().AddForce(base.transform.right * 0.01f);
						break;
					case 3:
						GetComponent<Rigidbody2D>().AddForce(-base.transform.right * 0.01f);
						break;
				}
			}
		}

		private void OnCollisionExit2D(Collision2D collision)
		{
			timer = 0f;
		}

		public override void OnLoad()
		{
			showBallBg();
		}

		public void showBallBg()
		{
			ballImg = GetComponent<Image>();
			if (GameData.useBallIndex < 0 || GameData.useBallIndex > 5)
			{
				GameData.useBallIndex = 0;
			}
			ballImg.sprite = ballSp[GameData.useBallIndex];
		}
	}
}

